﻿using System.Collections.Generic;

namespace ConsoleApplication3delegate
{
    class DepositCard         //储蓄卡
    {
        public int amount;

        public void Display()
        {
            Console.WriteLine("储蓄卡余额为：{0}", amount);
        }
        public void Account(int balance, int payday)
        {
            amount += balance;
            Console.WriteLine("取款{1}，储蓄卡余额为：{2}。", DateTime.Today.Day, balance, amount);
        }
    }

    class CreditCard           //信用卡
    {
        private int billamount;
        private int repaymentday;

        public CreditCard(int billamount, int repaymentday)
        {
            this.billamount = billamount;
            this.repaymentday = repaymentday;
        }

        public int getbillamount() { return billamount; }

        public int getrepaymentday() { return repaymentday; }

        public void Display() { Console.WriteLine("信用卡余额为：{0}", billamount); }


    }

    class CreditCardDelegate
    {
        public int billamount;  //信用卡余额
        public int repaymentday;
        public delegate void DelegateRepay(int billamount, int repaymentday);
        public event DelegateRepay Pay;
        public void Notify()
        {
            Console.Write("今天是{0}日,", DateTime.Today.Day);
            if (DateTime.Today.Day == repaymentday)
            {
                Pay(billamount, repaymentday);
                Console.WriteLine("还款成功！");
            }
            else
            {
                Console.WriteLine("未到还款日，无需还款！");
            }
        }

    }
    class Program
    {
        static void Main(string[] args)
        {
            DepositCard depositCard = new DepositCard();
            depositCard.amount = 10000;
            CreditCard creditCard1 = new CreditCard(-2000, 6);
            CreditCard creditCard2 = new CreditCard(-3000, 13);
            CreditCard creditCard3 = new CreditCard(-5000, 29);
            depositCard.Display(); Console.WriteLine("");  //输出储蓄卡余额
            List<CreditCard> Cards = new List<CreditCard>();
            Cards.Add(creditCard1); 
            Cards.Add(creditCard2); 
            Cards.Add(creditCard3);
            int i = 1;
            foreach (CreditCard card in Cards)
            {

                Console.WriteLine("信用卡开始执行委托还款。。。。。。");
                Console.WriteLine("信用卡creditCard{0}", i++);
                CreditCardDelegate hutu = new CreditCardDelegate();
                hutu.billamount = card.getbillamount();
                hutu.repaymentday = card.getrepaymentday();
                hutu.Pay += new CreditCardDelegate.DelegateRepay(depositCard.Account);
                hutu.Notify();
                depositCard.Display();
                Console.WriteLine("");
                depositCard.amount = 10000;
            }

            Console.ReadLine();
        }
    }
}